package com.xxx.loacl;

/**
 * @version v1.0
 * @Description
 * @Author admin
 * @date 2021/8/2  14:05
 * @Copyright
 */
public class TreadLocalDome {
    //    public static int num = 100
    public static ThreadLocal<Integer> local = new ThreadLocal<Integer>() {
        @Override
        protected Integer initialValue() {
            return 0;
        }
    };


    public static void main(String[] args) {
        new Thread() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    local.set(local.get() + 1);
                }
                System.out.println(Thread.currentThread().getName() + "," + local.get());

            }
        }.start();

        new Thread() {
            public void run() {
                for (int i = 0; i < 10; i++) {
                    local.set(local.get() + 1);
                }
                System.out.println(Thread.currentThread().getName() + "," + local.get());

            }
        }.start();
    }
}
